package com.meichis.yndms.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.text.TextUtils;

import com.meichis.mcsappframework.adapter.recyclerview.CommonAdapter;
import com.meichis.mcsappframework.adapter.recyclerview.base.ViewHolder;
import com.meichis.mcsappframework.widget.ZoomImageView;
import com.meichis.yndms.R;
import com.meichis.yndms.model.TallyPhotos;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import java.util.List;

public class TallyPhotosAdapter extends CommonAdapter<TallyPhotos> {

    private DisplayImageOptions options;
    private String type;
    private String subType;

    public void setType(String type, String subType) {
        this.type = type;
        this.subType = subType;
    }

    public TallyPhotosAdapter(Context context, int layoutId, List<TallyPhotos> datas) {
        super(context, layoutId, datas);

        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.emptyphoto)
                .showImageForEmptyUri(R.mipmap.emptyphoto)
                .showImageOnFail(R.mipmap.emptyphoto).cacheInMemory(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .cacheOnDisk(true).considerExifParams(true)
                .displayer(new RoundedBitmapDisplayer(16))    // 设置成圆角图片
                .build();
    }


    @Override
    protected void convert(ViewHolder holder, TallyPhotos tallyPhotos, int position) {
        holder.setText(R.id.tv_top, tallyPhotos.getTerminalName() + "（" + tallyPhotos.getPicState() + "）");
        holder.setText(R.id.tv_photoType, tallyPhotos.getPhotoTypeName());

        if (type.equals("全部") || type.equals("冰柜")) {
            holder.setVisible(R.id.tv_photoType, true);
        } else {
            if (subType.equals("全部")) {
                holder.setVisible(R.id.tv_photoType, true);
            } else {
                holder.setVisible(R.id.tv_photoType, false);
            }
        }

        ZoomImageView view = holder.getView(R.id.iv);

        view.displayImage(tallyPhotos.getImgUrl(), options);
    }
}
